function [diff,kappad_0,kappad_1,Ad_0,Ad_2] = mean_pd_LL_RE(x , I)

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% This code calculates the log-linearized coefficients for EIS ~= 1
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

kappad_1 = exp(x)/(exp(x) + 1);

kappad_0 = log(1 + exp(x)) - x * kappad_1;

mu_m = log(I.delta) - 0.5 * (1 - I.gamma) * (1/I.psi - I.gamma) * I.sigma^2 - I.mu/I.psi;

Ad_2 = I.alpha/((1 - I.alpha) * kappad_1 - 1) ;

Ad_0 = (mu_m + kappad_0 + (kappad_1 * Ad_2 + 1) * I.alpha * I.mu_dc + (I.lambda - 1) * kappad_1 * Ad_2 * I.mu + I.lambda * I.mu...
     + 0.5 * (kappad_1 * Ad_2 + 1)^2 * I.sigma_d^2 + 0.5 * (-I.gamma + I.lambda + kappad_1 * Ad_2 * (I.lambda - 1))^2 * I.sigma^2)/(1 - kappad_1) ;

diff = x - Ad_0 - Ad_2 * I.d_c_mean;
 
end
